package com.qiuyuliantu.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qiuyuliantu.common.annotation.Log;
import com.qiuyuliantu.common.core.controller.BaseController;
import com.qiuyuliantu.common.core.domain.AjaxResult;
import com.qiuyuliantu.common.enums.BusinessType;
import com.qiuyuliantu.base.domain.QiuPlatforms;
import com.qiuyuliantu.base.service.IQiuPlatformsService;
import com.qiuyuliantu.common.utils.poi.ExcelUtil;
import com.qiuyuliantu.common.core.page.TableDataInfo;

/**
 * 平台Controller
 *
 * @author lmx
 * @date 2025-04-08
 */
@RestController
@RequestMapping("/base/platforms")
public class QiuPlatformsController extends BaseController
{
    @Autowired
    private IQiuPlatformsService qiuPlatformsService;

    /**
     * 查询平台列表（不拦截公网访问）
     */
    @GetMapping("/tool/tooList")
    public TableDataInfo tooList(QiuPlatforms qiuPlatforms)
    {
        startPage();
        List<QiuPlatforms> list = qiuPlatformsService.selectQiuPlatformsList(qiuPlatforms);
        return getDataTable(list);
    }

    /**
     * 查询平台列表一级分类（不拦截公网访问）
     */
    @GetMapping("/tool/firstLeveList")
    public List<String> firstLeveList()
    {
        List<String> list = qiuPlatformsService.selectFirstLeveList();
        return list;
    }

    /**
     * 查询平台列表
     */
    @PreAuthorize("@ss.hasPermi('base:platforms:list')")
    @GetMapping("/list")
    public TableDataInfo list(QiuPlatforms qiuPlatforms)
    {
        startPage();
        List<QiuPlatforms> list = qiuPlatformsService.selectQiuPlatformsList(qiuPlatforms);
        return getDataTable(list);
    }

    /**
     * 导出平台列表
     */
    @PreAuthorize("@ss.hasPermi('base:platforms:export')")
    @Log(title = "平台", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QiuPlatforms qiuPlatforms)
    {
        List<QiuPlatforms> list = qiuPlatformsService.selectQiuPlatformsList(qiuPlatforms);
        ExcelUtil<QiuPlatforms> util = new ExcelUtil<QiuPlatforms>(QiuPlatforms.class);
        util.exportExcel(response, list, "平台数据");
    }

    /**
     * 获取平台详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:platforms:query')")
    @GetMapping(value = "/{platformId}")
    public AjaxResult getInfo(@PathVariable("platformId") Long platformId)
    {
        return success(qiuPlatformsService.selectQiuPlatformsByPlatformId(platformId));
    }

    /**
     * 新增平台
     */
    @PreAuthorize("@ss.hasPermi('base:platforms:add')")
    @Log(title = "平台", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QiuPlatforms qiuPlatforms)
    {
        return toAjax(qiuPlatformsService.insertQiuPlatforms(qiuPlatforms));
    }

    /**
     * 修改平台
     */
    @PreAuthorize("@ss.hasPermi('base:platforms:edit')")
    @Log(title = "平台", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QiuPlatforms qiuPlatforms)
    {
        return toAjax(qiuPlatformsService.updateQiuPlatforms(qiuPlatforms));
    }

    /**
     * 删除平台
     */
    @PreAuthorize("@ss.hasPermi('base:platforms:remove')")
    @Log(title = "平台", businessType = BusinessType.DELETE)
	@DeleteMapping("/{platformIds}")
    public AjaxResult remove(@PathVariable Long[] platformIds)
    {
        return toAjax(qiuPlatformsService.deleteQiuPlatformsByPlatformIds(platformIds));
    }
}
